﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Passwords.Biz
{
    public class PasswordLabel : Entity
    {
        private int displayIndex;
        private bool isIndexModified;

      
        public PasswordLabel(int id, string name, int valueType, int index)
            : base(id, name)
        {
            this.displayIndex = index;
            this.ValueType = (ItemType)valueType;
        }

        public PasswordLabel()
            : base()
        {
            this.ValueType = ItemType.String;
        }

        public ItemType ValueType { get;  set; }
        public int DisplayIndex
        {
            get { return displayIndex; }
            set
            {
//                int oldIndex = displayIndex;
                displayIndex = value;
                OnPropertyChanged("DisplayIndex");
                isIndexModified = true;
                //Context.DisplayIndexChanged(this, oldIndex, value);
            }
        }

        public bool IsIndexModified { get { return isIndexModified; } }

        public void Save()
        {
            Context.Save(this);
            isIndexModified = false;
            EntityState = EntityState.Unchanged;
        }

        internal void SetDisplayIndexInternal(int i)
        {
            this.displayIndex = i;
        }

        public int GetAssociatedPasswords()
        {
            return Context.GetAssociatedPasswords(this);
        }

        public void Delete()
        {
            Context.Delete(this);
            EntityState = EntityState.Deleted;
        }
    }
}
